Compositing in computer graphics involves combining two or more images to form a resultant image. In its simplest form, compositing involves overlaying a foreground image on a background image, where both images contain no transparency. Wherever the foreground image covers the background image, the foreground color will replace the corresponding background color, and everywhere else the background color will remain intact. This resultant image becomes the new background image. A third non-transparent image can similarly be overlaid on this new background. This process can be repeated for any number of images and effectively describes the ubiquitous Painter's algorithm.
In areas where the two images overlap, where it is required that some combination of the foreground and background appear, things are more complicated, as the foreground and background colors need to be blended appropriately. The paper “Compositing Digital Images”, T. Porter, T. Duff, Computer Graphics, Vol. 18, No. 3 ACM 1984, codified twelve possible operations of compositing algebra. The compositing process can be generalized to combining the foreground and background images with Porter-Duff operators to form a new background image, and then repeating this process for any number of new foreground images.
This ‘back to front’ technique produces a correct result, but is potentially very computationally expensive. Output devices, such as a image displays, are usually thought of as being composed of discrete picture elements, or pixels. Given the traditional technique, the compositing operations must be performed on a per pixel basis. Writing to an image frame buffer is often particularly slow on many computer systems, and so a system which makes multiple writes to the same pixel faces a severe performance penalty. In addition, this can produce unsightly flicker on a display as the pixels are written to many times. Alternatively, the image may be generated in an off-screen buffer, but this requires additional memory to be allocated for the off-screen buffer, as well as extra time to transfer the off-screen buffer to the frame buffer.
Images being composited in modern applications are also increasing in complexity. Whereas once an image may have been a polygonal region of flat color, images are now often composed of blends or textures. Calculation of an image pixel in a blend or texture is expensive, and so a system that generates such values only to later completely replace them with different ones from a new image incurs a significant penalty. Modern images also contain more complicated transparency objects, commonly as blends.